<?php

use Doraemon\model\DesignerAuth;
use Doraemon\service\DingTalkAlert;
use Doraemon\tools\Log;

class SyncUserInfoAction extends ActionPlugin
{
	public function main()
	{
		// 调试日志
		Log::info('设计师个人信息变更', $this->messageBody);

		$message_data = $this->messageBody['data'];
		DingTalkAlert::sendTextMsg(DingTalkAlert::DESIGNER_PROFILE,
			json_encode($this->messageBody, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE));

		if (!empty($message_data['uid']) && !empty($message_data['nick'])) {
			DesignerAuth::updateInfo($message_data['uid'], [
				'nick' => $message_data['nick']
			]);
		}

		$this->setSuccess();
	}
}
